package com.yidu.best.basicSetup.accountset.controller;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.yidu.best.basicSetup.accountset.domain.AccountVo;
import com.yidu.best.basicSetup.accountset.domain.Account;
import com.yidu.best.basicSetup.accountset.service.AccountService;
/**
 * 现金控制器
 * @author liyikang
 *
 */

@Controller
@RequestMapping("/Account/")
public class AccountController {
	@Autowired
	AccountService accountService;
	
	public AccountController(){
		
	}

	public AccountService getAccountService() {
		return accountService;
	}     

	public void setAccountService(AccountService accountService) {
		this.accountService = accountService;
	}

	public AccountController(AccountService accountService) {
		super();
		this.accountService = accountService;
	}

	@RequestMapping(value="accountList",method = RequestMethod.GET)
	public String Account() {
		return "sys/Account/Account";
	}

	/**
	 * 分页查询
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="account",method = RequestMethod.GET)
	public Map<String, Object> selectAccount(AccountVo accountVo){
		Map<String,Object> map = new HashMap<String, Object>();
		map = accountService.findAccount(accountVo);
		return map;
	}
	
	/**
	 * 添加方法
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "accounts",method = RequestMethod.POST)
	public boolean addAccount(Account account) {
		int rs = accountService.addAccount(account);
		if(rs == 1) {
			return true;
		}
		return false;
	}
	/**
	 * 修改方法
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "account",method = RequestMethod.PUT)
	public boolean updateAccount(Account account) {
		//调用业务层修改方法
		int rs = accountService.updateAccount(account);
		//如何rs=1 则修改成功
		if(rs==1) {
			//跳到页面
			return true;
		}else {
			return false;
		}
		
	}

	/**
	 * 删除
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "account/{accountIds}", method = RequestMethod.DELETE)
	public boolean deleteAccount(@PathVariable("accountIds")String accountIds ) {
		//定义变量
		int rs=0;
		//定义数组接受前台返回的字符串数组 将,去掉
        String[] accountId = accountIds.split(",");
        //将接收的数组遍历
        for (int i = 0; i < accountId.length; i++) {
        	//调用业务层方法
        	rs = accountService.deleteAccount(accountId[i]);
        }
        if(rs==1) {
        	return true;
        }
        return false;
	}
	
	
	
}
